<template>
  <div class="container">
    <div class="title" @click="back"><img src="../../../assets/image/back.png" alt=""></div>
    <input class="input" placeholder="" @input="itemInput"/>
    <div @click="confirm" class="confirm">确认</div>
  </div>
</template>

<script>
import {requestChange} from "../../../network/request";

export default {
  name: "change",
  data() {
    return {
      info: ''
    }
  },
  methods: {
    itemInput(e) {
      this.info = e.target.value
    },
    confirm() {
      let that = this
      let token = localStorage.getItem('token')
      if (that.info) {
        requestChange([token, that.info, that.name]).then(res => {
          that.$toast('修改成功！')
          let userInfo = JSON.parse(localStorage.getItem('userInfo'))
          userInfo[that.name] = that.info
          localStorage.setItem('userInfo',JSON.stringify(userInfo))
          setTimeout(()=>{
            this.$router.back()
          },1000)
        })
      } else {
        that.$toast('请输入内容！')
      }

    },
    back(){
      this.$router.back()
    }
  },
  mounted() {
    this.name = this.$route.query.name
  }
}
</script>

<style scoped>
.container {
  height: 100vh;
  width: 100%;
  background: url("../../../../src/assets/image/background.png") no-repeat;
  background-size: 100% 100%;
  margin: 0;
  padding: 0;
}

.input {
  width: 100%;
  background-color: #323658;
  color: white;
  height: 50px;
  text-align: center;
  font-size: 20px;
  margin-top: 50px;
  border-radius: 20px;
}

.confirm {
  width: 20%;
  margin-left: 40%;
  height: 40px;
  line-height: 40px;
  margin-top: 30px;
  text-align: center;
  font-size: 25px;
  color: white;
  background-color: gray;
  border-radius: 20px;
}

.title {
  margin-top: 10px;
  margin-left: 20px;
  position: absolute;
}
</style>
